﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.Composition;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Profiles.IPresenters;
using SonCa.SocialNetwork.Profiles.Presenters;
using Core.Interfaces;
using Core.DataAccess;

namespace SonCa.SocialNetwork.Profiles
{
    public partial class UploadAvatar : System.Web.UI.Page, IUploadAvatar
    {       
        private UploadAvatarPresenter _presenter;

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new UploadAvatarPresenter();           
            _presenter.Init(this);
        }

        public void ShowMessage(string Message)
        {
            lblMessage.Text = Message;
        }
        public void ShowApprovePanel()
        {
            pnlCrop.Visible = false;
            pnlUpload.Visible = false;
            pnlApprove.Visible = true;
        }

        public void ShowUploadPanel()
        {
            pnlCrop.Visible = false;
            pnlUpload.Visible = true;
            pnlApprove.Visible = false;
        }

        public void ShowCropPanel()
        {
            pnlCrop.Visible = true;
            pnlUpload.Visible = false;
            pnlApprove.Visible = false;
        }

        public void ShowAvatar(int accountID)
        {
            imgAvatar.ImageUrl = "~/Images/ProfileAvatar/ProfileImage.aspx?AccountID=" + accountID.ToString();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (fuAvatarUpload.PostedFile != null || !string.IsNullOrEmpty(fuAvatarUpload.PostedFile.FileName))
            {
                _presenter.UploadFile(fuAvatarUpload.PostedFile, "~/Profiles/Profile.aspx");
            }
        }

        protected void btnCrop_Click(object sender, EventArgs e)
        {
            _presenter.CropFile(Convert.ToInt32(hidX1.Value),
               Convert.ToInt32(hidY1.Value),
               Convert.ToInt32(hidWidth.Value),
               Convert.ToInt32(hidHeight.Value));   
        }

        protected void btnStartNew_Click(object sender, EventArgs e)
        {
            _presenter.StartNewAvatar();
        }

        protected void btnComplete_Click(object sender, EventArgs e)
        {
            _presenter.Complete();
        }

        public void CloseDialog()
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "close", "closeDialog();", true);
        }

        public void ShowInfo(Account account, WorkPlace workPlace)
        {

        }
    }
}